<?php

$TNTabCssWriteFlag = 0 ;

class TabNews{
	
	var $id ;
	var $sortSql ;
	var $itemSql ;
	var $itemSize = 5 ;
	var $itemImg = "";
	var $sortLinkUrl ;
	var $itemLinkUrl ;
	var $groupImgWidth = 130;
	var $groupImgStyle = " style='width:120px;height:90px;border:gray 1px solid;'";
	var $lightTabBGColor = "";
	var $lightTabTXTColor = "";
	var $blurTabBGColor = "";
	var $blurTabTXTColor = "";


	function TabNews($id){
		$this->id = $id ;
		$this->lightTabBGColor = getRGBColor(96);
		$this->lightTabTXTColor = getRGBColor(30);
		$this->blurTabBGColor = getRGBColor(88);
		$this->blurTabTXTColor = getRGBColor(10);
	}

	function setSortSql($sql){
		$this->sortSql = $sql ;
	}

	function setItemSql($sql){
		$this->itemSql = $sql ;
	}

	function setItemImg($img){
		$this->itemImg = $img ;
	}

	function getSortLinkUrl($url){
		$this->sortLinkUrl = $url ;
	}

	function getItemLinkUrl($url){
		$this->itemLinkUrl = $url ;
	}

	function setItemSize($size){
		$this->itemSize = $size ;
	}

	function setGroupImgWidth($width){
		$this->groupImgWidth = $width ;
	}

	function setGroupImgStyle($style){
		$this->groupImgStyle = $style ;
	}

	function getHTML(){
		if($this->sortSql == ""){
			return "";
		}
		$html = "";
		$matrix = get_result($this->sortSql);

		$html .= "<TABLE style='width:100%;margin-bottom:5px;'>" ;
		$html .= "<TR>";

		$temp = "text-align:center;border-right:white 1px solid;padding:2px 8px 0px 8px;color:" ;

		for($i=0;$i<count($matrix);$i++){

			$style = $temp . $this->blurTabTXTColor . ";background-color:" . $this->blurTabBGColor . ";";
			if($i == 0){
				$style = $temp . $this->lightTabTXTColor . ";background-color:" . $this->lightTabBGColor . ";";
			}

			$cstring = "this,'".$this->id."','".$this->lightTabBGColor."','".$this->lightTabTXTColor."','".$this->blurTabBGColor."','".$this->blurTabTXTColor."'";

			$html .= "	<TD style='". $style ."' id='TNTab_". $this->id ."_". $i ."' onmouseover=\"changeTNStyle(".$cstring.")\">" ;
			$html .= "		<div style='width:70px;cursor:pointer;'>";
			$html .=			$matrix[$i][1];
			$html .= "		</div>";
			$html .= "	</TD>" ;

			
		}
		$html .= "	<TD style='width:96%' style='background-color:". $this->blurTabBGColor .";'>&nbsp;</TD>" ;
		$html .= "</TR>" ;
		$html .= "<TR>" ;
		$html .= "	<TD colspan='". (count($matrix)*2+1) ."' style='background-color:".$this->lightTabBGColor.";'>";
		

		$girl = new gridBean();
		$girl->init($this->itemSql,1,1000);
		
		for($i=0;$i<count($matrix);$i++){
			$id = $matrix[$i][0];

			$index = 0 ;

			$display = "none";
			if($i == 0){
				$display = "block";
			}

			$icon = $matrix[$i][2];

			$html .= "<div id='TNDiv_". $this->id ."_". $i ."' class='TNTabDiv' style='display:". $display .";'>";
			$html .= "		<table style='width:100%;'>";
			$html .= "		<TR>" ;
			$html .= "			<TD><div style='width:". $this->groupImgWidth ."px;padding:5px;'><img src='". $icon ."'". $this->groupImgStyle ."></img></div></TD>";
			$html .= "			<TD style='width:96%;'>";
			for($n=0;$n<$girl->getFetchRows();$n++){
				if($girl->getCol($n,1) != $id){
					continue ;
				}
				if($index > $this->itemSize){
					break ;
				}
				
				if($index > 0){
					$html .= "<br>";
				}

				if($this->itemImg != ""){
					$html .= "		&nbsp;<img src='". $this->itemImg ."'></img> ";
				}

				$html .= "			<a href='". $this->itemLinkUrl ."?button_". $girl->getFieldName(0) ."=". $girl->getCol($n,0) ."'>";
				$html .=			$girl->getCol($n,2);
				$html .= "			</a>";

				$index++ ;
			}
			$html .= "			</TD>";
			$html .= "		</TR>" ;
			$html .= "		</TABLE>";
			$html .= "</div>";

		}
		

		$html .= "	</TD>" ;
		$html .= "</TR>" ;
		$html .= "</TABLE>";
		
		unset($girl);
		unset($matrix);

		return $html ;		
	}

}

?>